#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <dirent.h>

#include <coap2/coap.h>

#ifndef _COAP_RESOURCE_H_
#define _COAP_RESOURCE_H_

#ifdef __GNUC__
#define UNUSED_PARAM __attribute__ ((unused))
#else /* not a GCC */
#define UNUSED_PARAM
#endif /* GCC */

/*
@descryption:
  Return the coap message, need free by youself

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
const char* obtain_coap_message();

/*
@descryption:
   Register coap message handler from client

@param: des: Copy message to destance 
        Note that pointer will auto free  
@Author: jiang_c
@Datetime: Thu Dec 26 2024
*/
typedef void  
(*REGISTER_MESSAGE_HANDLER)(char** des);

extern
REGISTER_MESSAGE_HANDLER register_message_handler;


/*
@descryption:
  client put message to server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_put_data(coap_context_t *ctx UNUSED_PARAM,
              struct coap_resource_t *resource,
              coap_session_t *session,
              coap_pdu_t *request,
              coap_binary_t *token,
              coap_string_t *query UNUSED_PARAM,
              coap_pdu_t *response);

/*
@descryption:
  client put time to server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_put_time(coap_context_t *ctx UNUSED_PARAM,
             struct coap_resource_t *resource,
             coap_session_t *session UNUSED_PARAM,
             coap_pdu_t *request,
             coap_binary_t *token UNUSED_PARAM,
             coap_string_t *query UNUSED_PARAM,
             coap_pdu_t *response);

/*
@descryption:
  client put unknow message to server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_unknown_put(coap_context_t *ctx,
                coap_resource_t *resource UNUSED_PARAM,
                coap_session_t *session,
                coap_pdu_t *request,
                coap_binary_t *token,
                coap_string_t *query,
                coap_pdu_t *response);

/*
@descryption:
  client get async with server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_get_async(coap_context_t *ctx,
              struct coap_resource_t *resource UNUSED_PARAM,
              coap_session_t *session,
              coap_pdu_t *request,
              coap_binary_t *token UNUSED_PARAM,
              coap_string_t *query UNUSED_PARAM,
              coap_pdu_t *response);

/*
@descryption:
  client get resource from server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_get_index(coap_context_t *ctx UNUSED_PARAM,
              struct coap_resource_t *resource,
              coap_session_t *session,
              coap_pdu_t *request,
              coap_binary_t *token,
              coap_string_t *query UNUSED_PARAM,
              coap_pdu_t *response);

/*
@descryption:
  client get time from server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_get_time(coap_context_t  *ctx UNUSED_PARAM,
             struct coap_resource_t *resource,
             coap_session_t *session,
             coap_pdu_t *request,
             coap_binary_t *token,
             coap_string_t *query,
             coap_pdu_t *response);

/*
@descryption:
  delete time from server

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
hnd_delete_time(coap_context_t *ctx UNUSED_PARAM,
                struct coap_resource_t *resource UNUSED_PARAM,
                coap_session_t *session UNUSED_PARAM,
                coap_pdu_t *request UNUSED_PARAM,
                coap_binary_t *token UNUSED_PARAM,
                coap_string_t *query UNUSED_PARAM,
                coap_pdu_t *response UNUSED_PARAM);
/*
@descryption:
  check if need async communication or not

@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/
void
check_async(coap_context_t *ctx,
            coap_tick_t now);
#endif
